<?php
declare (strict_types = 1);

namespace app\controller;

use app\model\Month as ModelMonth;
use think\Request;

class Month
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(ModelMonth $re)
    {   
        $res = $re->sel();
        if($res){
            return json(['code'=>1,'data'=>$res]);
        }
        return json(['code'=>0,'data'=>'']);

    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request,ModelMonth $re)
    {
        $data['goods_name'] = $request->param('goods_name');
        $data['goods_type'] = $request->param('goods_type');
        $data['store_count'] = $request->param('store_count');
        $data['is_show'] = $request->param('is_show');
        $data['is_hot'] = $request->param('is_hot');
        $res = $re->add($data);
        if($res){
            return json(['code'=>1,'data'=>'成功！']);
            
        }
        return json(['code'=>0,'data'=>'失败']);

    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request,$id,ModelMonth $re)
    {
        $where['goods_id'] = $id;
        $data['goods_name'] = $request->param('goods_name','默认');
        $data['goods_type'] = $request->param('goods_type','默认');
        $data['store_count'] = $request->param('store_count','默认');
        $data['is_show'] = $request->param('is_show','默认');
        $data['is_hot'] = $request->param('is_hot','默认');
        $res = $re->upd($where,$data);
        if($res){
            return json(['code'=>1,'data'=>'成功！']);
            
        }
        return json(['code'=>0,'data'=>'失败']);
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id,ModelMonth $re)
    {
        $data['goods_id']= $id;
        $res = $re->del($data);
        if($res){
            return json(['code'=>1,'data'=>'成功！']);
            
        }
        return json(['code'=>0,'data'=>'失败']);
    }
}
